import * as PIXI from 'pixi.js'
import { BaseCard } from "../card/baseCard";
import { CardType } from "@/share/commonType";
let TextureCache = PIXI.utils.TextureCache
interface CardListProps {
    cardList: CardType[],
    posX: number,
    posY: number,
    cardSpacing?: number,
    isLandCard?: boolean;
    scaleSize?: number
}
export class CardList {
    container: PIXI.Container = new PIXI.Container()
    constructor(FaContainer: PIXI.Container) {
        FaContainer.addChild(this.container)
    }
    changeCard(props: CardListProps) {
        this.clearCard()
        if (props.cardList) { // 渲染用户出牌
            this.container.x = props.posX
            this.container.y = props.posY
            props.cardList.forEach(({ cardNum, cardIcon }, index) => {
                let baseCardProps = {
                    cardNum,
                    cardIcon,
                    container: this.container,
                    posX: index * (props.cardSpacing || 30 * props.scaleSize),
                    scale: 0.7 * props.scaleSize,
                    isLandCard: props.isLandCard,
                }
                new BaseCard(baseCardProps)
            })
        } else { // 渲染不出
            this.container.x = props.posX
            this.container.y = props.posY + 50 * props.scaleSize
            let skipSprite = new PIXI.Sprite(TextureCache['skip'])
            skipSprite.scale.set(props.scaleSize)
            this.container.addChild(skipSprite)
        }
    }
    clearCard() {
        this.container.removeChildren()
    }
}